home *** CD-ROM | disk | FTP | other *** search
- class Enemy extends Car
- {
- var distance;
- var sEnemy;
- var energy;
- var deadDelay;
- var dropTime;
- var runTime;
- var bOnScreen;
- var mcCar;
- var mcEnergy;
- var mcCanvas;
- var pos;
- var width;
- var turnDelay;
- var turnTime;
- var autoTurnFactor;
- var turnDir;
- var bDestroyed;
- var vel;
- var velMod;
- var height;
- var mcDamage;
- var bFromWeapon;
- var maxVel;
- var blinkInd;
- var frame;
- var firstFrame;
- function Enemy(distanceNew, sEnemyNew, newPos, newVel, mcCanvasNew, depth)
- {
- super("enemy " + sEnemyNew,newPos,newVel,mcCanvasNew,depth);
- this.distance = distanceNew;
- this.sEnemy = sEnemyNew;
- this.energy = 10;
- this.deadDelay = 0;
- this.dropTime = 40;
- this.runTime = 0;
- this.bOnScreen = false;
- this.mcCar.gotoAndStop("alive");
- this.mcEnergy = this.mcCanvas.attachMovie("boss energy","mcEnergy",depth + 1);
- }
- function setFramesRange(Void)
- {
- }
- function step(player, plDist, bmpShoulder)
- {
- if(plDist > this.distance)
- {
- super.step(player.pos,player.vel,bmpShoulder);
- var _loc6_ = player.pos.x - this.pos.x;
- var _loc4_ = player.pos.y - this.pos.y;
- if(Math.abs(_loc6_) < this.width && this.turnDelay > 15)
- {
- this.turnDelay = 15;
- this.turnTime = 15;
- this.autoTurnFactor = 5;
- this.turnDir = Math.random() >= 0.5 ? 1 : -1;
- }
- if(!this.bDestroyed)
- {
- if(player.vel.y < 12)
- {
- this.vel.y = 12;
- }
- else if(player.pos.y + 20 < this.pos.y)
- {
- _loc4_ = this.pos.y - player.pos.y;
- if(_loc4_ < 100 || this.runTime > 0)
- {
- if(this.runTime == 0)
- {
- this.runTime = 10 + Math.round(20 * Math.random());
- var _loc5_ = 24 - player.vel.y;
- this.velMod = player.vel.y - 2 + _loc5_ * Math.random();
- }
- else
- {
- this.runTime = this.runTime - 1;
- }
- this.vel.y = this.velMod;
- }
- else
- {
- this.vel.y = player.vel.y - 1;
- }
- }
- else
- {
- this.vel.y = player.vel.y + 5;
- }
- }
- if(this.pos.y < -50)
- {
- if(this.bDestroyed)
- {
- this.die();
- }
- else
- {
- this.pos.y = -50;
- this.vel.y = player.vel.y;
- this.onOutOfScreenV();
- }
- }
- else if(this.pos.y > Game.screenH + 50)
- {
- if(this.bDestroyed)
- {
- this.die();
- }
- else
- {
- this.pos.y = Game.screenH + 50;
- this.vel.y = 5;
- this.onOutOfScreenV();
- }
- }
- if(this.pos.y > -50 && this.pos.y < Game.screenH + 50)
- {
- this.bOnScreen = true;
- }
- if(this.bOnScreen)
- {
- if(this.dropTime > 0)
- {
- this.dropTime = this.dropTime - 1;
- }
- else if(!this.bDestroyed)
- {
- this.dropTime = 60 + Math.round(60 * Math.random());
- Game.getInstance().createObstacle();
- }
- }
- }
- }
- function draw(Void)
- {
- this.mcCar._x = this.pos.x;
- this.mcCar._y = Game.screenH - this.pos.y;
- this.mcEnergy._x = this.mcCar._x;
- this.mcEnergy._y = this.mcCar._y - this.height / 2 - 10;
- this.mcEnergy.mcBar._xscale += (100 * this.energy / 10 - this.mcEnergy.mcBar._xscale) * 0.4;
- this.mcDamage._x = this.mcCar._x;
- this.mcDamage._y = this.mcCar._y;
- if(this.bDestroyed)
- {
- if(this.sEnemy == "rac" || !this.bFromWeapon)
- {
- this.mcCar._rotation += this.vel.y >= 2 ? this.vel.y * 3 : 6;
- }
- else if(this.sEnemy == "aa")
- {
- this.mcCar._x += 4 * (1 - 2 * Math.random());
- }
- }
- else
- {
- this.mcCar._rotation = this.vel.x * Math.ceil(this.vel.y / this.maxVel);
- }
- }
- function getDamage(value)
- {
- if(this.blinkInd == 0)
- {
- this.blinkInd = 10;
- if(value != undefined)
- {
- this.energy -= value;
- }
- else
- {
- this.energy -= 1;
- }
- }
- if(this.energy <= 0 && !this.bDestroyed)
- {
- this.energy = 0;
- this.vel.y /= 2;
- if(!(!this.bFromWeapon && this.sEnemy == "churchil"))
- {
- this.mcCar.gotoAndStop("dead");
- }
- this.mcEnergy._visible = false;
- this.bDestroyed = true;
- Game.getInstance().protectPlayer();
- switch(this.sEnemy)
- {
- case "directLine":
- this.deadDelay = 7;
- break;
- case "churchil":
- this.blinkInd = 0;
- break;
- case "elephant":
- this.deadDelay = 6;
- break;
- case "lloyd":
- this.deadDelay = 6;
- }
- if(this.bFromWeapon)
- {
- Game.getInstance().addPoints(5000);
- Game.getInstance().showBonus();
- }
- else
- {
- Game.getInstance().addPoints(1000);
- Game.getInstance().showPoints(this.pos,1000);
- }
- }
- else if(this.energy > 0)
- {
- this.bFromWeapon = false;
- if(this.sEnemy == "directLine" || this.sEnemy == "sainsbury")
- {
- var _loc2_ = this.mcCar.getDepth() + 2;
- this.mcDamage = this.mcCanvas.attachMovie("car damage","mcDamage" + _loc2_,_loc2_);
- this.mcDamage.gotoAndStop(this.sEnemy);
- }
- }
- }
- function die(Void)
- {
- Game.getInstance().onEnemyDead();
- }
- function remove(Void)
- {
- this.mcCar.removeMovieClip();
- this.mcEnergy.removeMovieClip();
- this.mcDamage.removeMovieClip();
- false;
- }
- function modifyVelocity(plVel)
- {
- if(this.deadDelay > 0)
- {
- this.deadDelay = this.deadDelay - 1;
- this.vel.y = plVel.y;
- }
- else if(this.bFromWeapon)
- {
- switch(this.sEnemy)
- {
- case "tesco":
- this.vel.x = 0;
- this.vel.y = plVel.y - 5;
- break;
- case "directLine":
- this.vel.x = 0;
- this.vel.y = plVel.y - 5;
- break;
- case "elephant":
- this.vel.x = -3;
- this.vel.y = plVel.y + 15;
- break;
- case "sainsbury":
- this.vel.x = 0;
- this.vel.y = plVel.y - 5;
- break;
- case "churchil":
- this.vel.x = 0;
- this.vel.y = plVel.y - 20;
- break;
- case "moreThan":
- this.vel.x = 0;
- this.vel.y = plVel.y + 15;
- break;
- case "asda":
- this.vel.x -= 20;
- this.vel.y = plVel.y + 2;
- break;
- case "lloyd":
- this.vel.x = 0;
- this.vel.y = plVel.y + 15;
- break;
- default:
- this.vel.y = plVel.y - 10;
- if(this.pos.x > 275)
- {
- this.vel.x = 5;
- break;
- }
- this.vel.x = -5;
- break;
- }
- }
- else if(this.pos.x > 275)
- {
- this.vel.x = 5;
- }
- else
- {
- this.vel.x = -5;
- }
- }
- function onOutOfScreenV(Void)
- {
- this.bOnScreen = false;
- }
- function onOutOfScreenH(Void)
- {
- if(!this.bDestroyed)
- {
- this.pos.y = -50;
- this.pos.x = 275;
- }
- else
- {
- this.mcCar._visible = false;
- this.mcEnergy._visible = false;
- this.die();
- }
- }
- function checkWeapon(mcWeapon)
- {
- var _loc2_ = Game.getInstance().sEnemy;
- if((_loc2_ == "directLine" || _loc2_ == "aa") && mcWeapon.hitTest(this.mcCar._x,this.mcCar._y) || _loc2_ != "directLine" && _loc2_ != "aa" && mcWeapon.hitTest(this.mcCar))
- {
- this.bFromWeapon = true;
- var _loc3_ = !Application.bEasy ? 3 : 5;
- this.getDamage(_loc3_);
- this.setFramesRange();
- this.frame = this.firstFrame;
- if(_loc2_ == "sainsbury")
- {
- Game.getInstance().removeShot();
- }
- }
- }
- }
-